var VSCodeHistoryHelper = (function () {
    function getBinUrls(commit, version) {
        var baseUrl = "https://vscode.cdn.azure.cn/";

        function getBaseCommonUrl(commit, version) {
            if (!commit || !version) return null;
            return baseUrl + "stable/" + commit;
        }

        // function getLinuxUrls(commit, version) {
        //     var baseCommonUrl = getBaseCommonUrl(commit, version);
        //     if (!baseCommonUrl) return;
        //
        //     // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/code_1.32.3-1552606978_amd64.deb
        //     var deb64 = baseCommonUrl + "/code_" + version + "-1552606978_amd64.deb";
        //     // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/code_1.32.3-1552604880_i386.deb
        //     var deb32 = baseCommonUrl + "/code_" + version + "-1552604880_i386.deb";
        //     // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/code-1.32.3-1552607091.el7.x86_64.rpm
        //     var rpm64 = baseCommonUrl + "/code-" + version + "-1552607091.el7.x86_64.rpm";
        //     // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/code-1.32.3-1552605012.el7.i386.rpm
        //     var rpm32 = baseCommonUrl + "/code-" + version + "-1552605012.el7.i386.rpm";
        //     // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/code-stable-1552606946.tar.gz
        //     var targz64 = baseCommonUrl + version + "/code-stable-1552606946.tar.gz";
        //     // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/code-stable-1552604844.tar.gz
        //     var targz32 = baseCommonUrl + version + "/code-stable-1552604844.tar.gz";
        //
        //     return {
        //         deb64: deb64,
        //         deb32: deb32,
        //         rpm64: rpm64,
        //         rpm32: rpm32,
        //         targz64: targz64,
        //         targz32: targz32
        //     }
        // }

        function getMacUrls(commit, version) {
            var baseCommonUrl = getBaseCommonUrl(commit, version);
            if (!baseCommonUrl) return;
            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCode-darwin-stable.zip
            return {
                zip: baseCommonUrl + "/VSCode-darwin-stable.zip"
            }
        }

        function getWinUrls(commit, version) {
            var baseCommonUrl = getBaseCommonUrl(commit, version);
            if (!baseCommonUrl) return;

            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCodeSetup-x64-1.32.3.exe
            var sys64 = baseCommonUrl + "/VSCodeSetup-x64-" + version + ".exe";
            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCodeSetup-ia32-1.32.3.exe
            var sys32 = baseCommonUrl + "/VSCodeSetup-ia32-" + version + ".exe";

            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCodeUserSetup-x64-1.32.3.exe
            var user64 = baseCommonUrl + "/VSCodeUserSetup-x64-" + version + ".exe";
            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCodeUserSetup-ia32-1.32.3.exe
            var user32 = baseCommonUrl + "/VSCodeUserSetup-x64" + version + ".exe";

            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCode-win32-x64-1.32.3.zip
            var zip64 = baseCommonUrl + "/VSCode-win32-x64-" + version + ".zip";
            // https://vscode.cdn.azure.cn/stable/a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4/VSCode-win32-ia32-1.32.3.zip
            var zip32 = baseCommonUrl + "/VSCode-win32-ia32-" + version + ".zip";

            return {
                sys64: sys64,
                sys32: sys32,
                user64: user64,
                user32: user32,
                zip64: zip64,
                zip32: zip32
            }
        }

        return {
            win: getWinUrls(commit, version),
            // linux: getLinuxUrls(commit, version),
            mac: getMacUrls(commit, version)
        }
    }

    function start() {
        var elReleaseEntitys = document.querySelectorAll(".release-entry .commit.Details");
        var result = [];
        for (var i = 0; i < elReleaseEntitys.length; i++) {
            var elReEntry = elReleaseEntitys[i];
            //标题
            var titleHref = elReEntry.querySelector(".commit-title>a").href;
            var title = titleHref.substring(titleHref.lastIndexOf("tag/") + 4);
            //时间
            var elLis = elReEntry.querySelectorAll("ul>li");
            var time = elLis[0].querySelector("*[datetime]").getAttribute("datetime");
            //commit号
            var cmmitHref = elLis[1].querySelector("a").href;
            var commit = cmmitHref.substring(cmmitHref.lastIndexOf("commit/") + 7);

            // var reZip = relis[2].querySelector(">a");
            // var reZip = relis[3].querySelector(">a");

            var binUrls = getBinUrls(commit, title);
            // console.log(title, binUrls);
            // result[title] = {bin: binUrls}
            result.push({version:title, bin: binUrls})
        }
        // console.log(result)
        var reslutWrap = document.querySelector(".resultMeMe");
        if (reslutWrap) {
            reslutWrap.remove();
        }
        document.body.innerHTML += '<div class = ".resultMeMe" style="position: absolute;z-index:999;right: 0;bottom: 0;width:200px;height: 200px"><textarea id="elInputResult"></textarea></div>';
        var elInputResult = document.getElementById("elInputResult");
        elInputResult.value = JSON.stringify(result);
        // document.write(JSON.stringify(result));
        // document.write(result.toString());
    }

    return {start: start};
})();
VSCodeHistoryHelper.start();
